require 'powncer.rb'
require 'open-uri'

def notes
    Note.find( '../public_note_lists/for/eggie5').note
end

def image_path(url)
    save_as = File.basename(url)
    open(url) do |r|
       open(save_as, 'wb') do |f|
          f.write(r.read)
       end
    end
    save_as
end

def growl(title, msg, img, pri=0, sticky="")
    #buggy in leopard, so I have to do it twice...
    system "growlnotify -n powncer --image \"#{img}\"  -p #{pri} -t \"#{title}\" -m \"#{msg}\""
    system "growlnotify -n powncer --image \"#{img}\"  -p #{pri} -t \"#{title}\" -m \"#{msg}\""
end

last_id = notes[0].id

loop do
  note = notes[0]
  unless note.id == last_id
      sender = note.sender
      path = "#{image_path(sender.profile_photo_urls.large_photo_url)}"
      growl "#{sender.username} Says:", note.body, path
    last_id = note.id
  end
  
  sleep(5)
end

#sudo tcpflow -i en1 host pownce.com